package 异常0907;
/*
用户输入两个整数，计算商
 */

import java.util.InputMismatchException;
import java.util.Scanner;

public class 输入数字为float型抛出异常 {
    public static void main(String[]args){
        Scanner i=new Scanner(System.in);//实例化Scann对象
        System.out.println("请输入两个整数：");
        try {
            float a=i.nextInt();//输入一个整数存入变量a中
            float b=i.nextInt();
            try {
                float c=a/b;
                if (String.valueOf(c).equals("Infinity")){
                    throw new ArithmeticException();//抛出异常
                }
                System.out.println("商为："+c);
            } catch (Exception e) {
                System.out.println("除数不能为0！");
            }
        } catch (Exception e) {
            System.out.println("只能输入整数！");
        }
    }
}
